﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using Corporation.Link;
using Solely;

public partial class admin_Corp_Link_LinkList : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("User", "C1");
        if (!IsPostBack)
        {
            Bind();
        }
     
    }
    private void Bind()
    {
        btnDelete.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
        string strWhere = "1=1";
        string TitleName = Base.GetRequest.Filter(txtKeyWord.Text.Trim());
        string CompanyName =Base.GetRequest.Filter(txtCompany.Text.Trim());
        if (TitleName != "")
            strWhere += " and Name like '%" + TitleName + "%'";
        if (CompanyName != "")
            strWhere += " and CompanyName like '%" + CompanyName + "%'";
 
        if (Request.QueryString["ID"] != null)
        {
            if (Request.QueryString["UserID"] != null)
                this.HiddUserID.Value = Request.QueryString["UserID"].ToString();
           //int id = int.Parse(Request.QueryString["ID"].ToString());
           //TLink TLink = RLink.GateItem(id);
           //txtName.Text = TLink.Name;
           // txtUrl.Text = TLink.Url;
           // ImgUrl1.Value = ProcessImageUrl(TLink.Logo.ToString());
           //ImgUrl.Src = ProcessAbsoluteUrl(TLink.Logo.ToString());
           //tbLinkAdd.Style.Add("display:", "block");
        }



        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strURl;
        if (Request.QueryString["page"] != null)
        {
            PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
            PageNo1.PageSize = 12;
            if (Session["strWhere"] != null)
            {
                PageNo1.Where = Session["strWhere"].ToString();
            }
            else
            {
                PageNo1.Where = "1=1";
            }
            PageNo1.Table = "U_UserInfo INNER JOIN U_UserLink  ON U_UserInfo.UserID = U_UserLink.UserID";
            PageNo1.FldName = "AddDate";
            PageNo1.StrGetFields = "U_UserInfo.CompanyName,U_UserLink.*";
            DataTable table = PageNo1.BindView();
            grdUserLink.DataSource = table.DefaultView;
            grdUserLink.DataBind();
        }
        else
        {
            PageNo1.Pageindex = 1;
            PageNo1.PageSize = 12;
            PageNo1.Where = "1=1";
            PageNo1.Table = "U_UserInfo INNER JOIN U_UserLink  ON U_UserInfo.UserID = U_UserLink.UserID";
            PageNo1.FldName = "AddDate";
            PageNo1.StrGetFields = "U_UserInfo.CompanyName,U_UserLink.*";
            DataTable table = PageNo1.BindView();
            grdUserLink.DataSource = table.DefaultView;
            grdUserLink.DataBind();
        }
    }

    protected void lbtnUpdate_Command(object sender, CommandEventArgs e)
    {
       
        TLink TLink = new TLink();
        string Content = e.CommandArgument.ToString();
        int index = Content.IndexOf("|");
        if (index < -1 || index + 1 > Content.Length)
            return;

        TLink.ID = int.Parse(Content.Substring(0, index));
        TLink.Verify = Convert.ToBoolean(Content.Substring(index + 1));
        ILink RLink = new RLink();
        RLink.UpdateVerify(TLink);
        Bind();
    }
    
    protected void grdUserLink_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
            e.Row.Attributes.Add("onMouseOut", "SetOldColor(this)");
            LinkButton btn = (LinkButton)e.Row.FindControl("lbtnUpdate");
            if (btn.Text == "已审")
                btn.Attributes.Add("onclick", "javascript:return confirm('您确认要取消审核吗？')");
            else
                btn.Attributes.Add("onclick", "javascript:return confirm('您确认要让该会员通过审核吗？')");
           
        }
    }
    protected void grdUserLink_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdUserLink.PageIndex = e.NewPageIndex;
        Bind();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdUserLink.Rows.Count; i++)
        {
            CheckBox cbox=(CheckBox)grdUserLink.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = int.Parse(grdUserLink.DataKeys[i].Value.ToString());
                ILink RLink = new RLink();
                RLink.Delete(id);
            }
        }
        Bind();
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        string strWhere = " where 1=1";
        string TitleName = txtKeyWord.Text.Trim();
        string CompanyName = txtCompany.Text.Trim();
        if (TitleName != "")
            strWhere += " and Name like '%" + Base.GetRequest.Filter(TitleName) + "%'";
        if (CompanyName != "")
            strWhere += " and CompanyName like '%" + Base.GetRequest.Filter(CompanyName) + "%'";
        ILink RLink = new RLink();
        DataTable dt = RLink.GetDataTable(strWhere);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "<font color='red'>暂无数据</font>";
        }
        else
            lblMessage.Visible = false;
        grdUserLink.DataSource = dt.DefaultView;
        grdUserLink.DataBind();
    }
    protected void grdUserLink_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = int.Parse(grdUserLink.DataKeys[e.RowIndex].Value.ToString());
        ILink RLink = new RLink();
        RLink.Delete(id);
        Bind();
    }

    public string GetNewUrl(string Url)
    {
        return ProcessImageUrl(Url);
    }
}
